//
//  StoreInformationFourTableViewCell.m
//  GLGW_Shoping
//
//  Created by whx on 2018/12/10.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "StoreInformationFourTableViewCell.h"
#import "GLGWTagsView.h"

@implementation StoreInformationFourTableViewCell
{
    GLGWTagsView * tageView;
    GLGWView *baView;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        GLGWView *baV = [[GLGWView alloc] initWithInSuperView:self.contentView];
        [baV mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(self.contentView);
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(59)));
            make.bottom.equalTo(self.contentView);
        }];
        baView = baV;
    }
    return self;
}

- (void)setDataArr:(NSMutableArray *)dataArr
{
    _dataArr = dataArr;
    FFTagsViewConfig *config = [self tagViewConfig];
   
    if (tageView) {
        [tageView removeFromSuperview];
        tageView = nil;
    }
    
    tageView = [[GLGWTagsView alloc] initWithFrame:CGRectMake(kWidthProportion_In_iPhoneTriploid(4), kHeightProportion_In_iPhoneTriploid(7), KScreenWidth - kHeightProportion_In_iPhoneTriploid(8), 0) tagsArray:dataArr config:config tagBackImgStr:@"icon_quxiaoyoushi"];
    kWeakSelf(self);
    tageView.tagBtnClickedBlock = ^(GLGWTagsView * _Nonnull aTagsView, UIButton * _Nonnull sender, NSInteger tag) {
        [weakself tapTagsView:sender tag:tag];
    };
    [self.contentView addSubview:tageView];
    [self refreshCellHeight];
}

- (FFTagsViewConfig *)tagViewConfig
{
    FFTagsViewConfig *config = [[FFTagsViewConfig alloc] init];
    config.itemHeight = kHeightProportion_In_iPhoneTriploid(32);
    config.itemHerMargin = kWidthProportion_In_iPhoneTriploid(10);
    config.itemVerMargin = kHeightProportion_In_iPhoneTriploid(14);
    config.hasBorder = NO;
    config.itemContentEdgs = kWidthProportion_In_iPhoneTriploid(12);
    config.topBottomSpace = 0.1;
    config.fontSize = 14.0;
    config.isCanSelected = YES;
    config.isCanCancelSelected = NO;
    config.isMulti = YES;
    config.normalTitleColor = [UIColor colorWithHexString:@"#666666"];
    config.selectedTitleColor = [UIColor colorWithHexString:@"#666666"];
    return config;
}

- (void)refreshCellHeight
{
    CGFloat hei = [self cellHeight];
    [baView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(hei));
    }];
    [self.contentView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(hei));
    }];
}

- (CGFloat)cellHeight
{
    //获取底部分割view的最大Y值
    CGFloat taH = [tageView heighttagsArray:self.dataArr config:[self tagViewConfig]];
    CGFloat maxY = taH + kHeightProportion_In_iPhoneTriploid(7) + kHeightProportion_In_iPhoneTriploid(24);
    return maxY;
}

- (void)tapTagsView:(UIButton *)sender tag:(NSInteger)tag
{
    if (self.BlockTapTagsView) {
        self.BlockTapTagsView(sender, tag);
    }
}

@end
